﻿@{
    Layout = "_EmptyLayout";
    ViewData["Title"] = "Login";
}
<form class="layui-form layui-form-pane" action="" lay-filter="example" style="margin:20px">
    <div class="layui-form-item">
        <label class="layui-form-label">用户名</label>
        <div class="layui-input-inline">
            <input type="text" name="username" id="username" lay-verify="required" lay-reqtext="用户名是必填项，岂能为空？" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">密码</label>
        <div class="layui-input-inline">
            <input type="password" name="password" id="password" placeholder="请输入密码" lay-verify="required" lay-reqtext="密码是必填项，岂能为空？" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">类型</label>
        <div class="layui-input-block">
            <input type="radio" name="type" value="js" title="教  师" checked="">
            <input type="radio" name="type" value="zjc" title="政教处">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <input type="radio" name="type" value="xz" title="校  长">
            <input type="radio" name="type" value="cwc" title="财务处">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="submit" class="layui-btn" id="btn" lay-submit="" lay-filter="login">立即登录</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>

</form>
@section Scripts{
    <script src="~/layui-v2.5.5/layui/layui.js" charset="utf-8"></script>
    <script src="~/js/jquery.js"></script>
    <script src="~/js/md5.js"></script>
    <script type="text/javascript">
        $("#btn").click(function (event) {
            event.preventDefault()
        })
    </script>
    <script type="text/javascript">
        layui.use(['form'], function () {
            var form = layui.form
                , layer = layui.layer;
            form.on('submit(login)', function (data) {
                var username = data.field.username;
                var password = md5(data.field.password);
                var type = data.field.type;
                layer.msg('登录中', {
                    icon: 16
                    , shade: 0.01
                    , time: 5000
                });
                $.ajax({
                    url: '/Api/LogInJudge',
                    data: { username: username, password: password, type: type },
                    type: "GET",
                    dataType: "JSON",
                    success: function (data) {
                        var typeUpper = type.toUpperCase();
                        switch (data.code) {
                            case 200:
                                var indexLayer = parent.layer.open({
                                    type: 2,
                                    content: '/' + typeUpper,
                                    title: typeUpper,
                                    area: ['530px', '400px'],
                                    resize: true,
                                    scrollbar: false,
                                });
                                parent.layer.full(indexLayer);
                                break;
                            case 270:
                            case 100:
                            case 210:
                                layer.msg(data.msg, function () {
                                });
                                break;
                            default:
                                layer.msg("我也不知道怎么了，你再试试呗", function () {
                                });
                        }
                    }
                })

            });
        });
    </script>
}
